#ifndef _honrun_printf_H_
#define _honrun_printf_H_


typedef char* honrun_va_list;

#define __honrun_INTSIZEOF(n)       ( (sizeof(n) + sizeof(int64_t) - 1) & ~(sizeof(int64_t) - 1) )

#define __honrun_va_start(ap, v)    ((void)(ap = (honrun_va_list)(&(v)) + __honrun_INTSIZEOF(v)))

#define __honrun_va_arg(ap, t)      (*(t*)((ap += __honrun_INTSIZEOF(t)) - __honrun_INTSIZEOF(t)))

#define __honrun_va_end(ap)         ((void)(ap = (honrun_va_list)0))


struct printf_info {
    char *bf;	/* Digit buffer */
    char zs;	/* non-zero if a digit has been written */
    char *outstr;	/* Next output position for sprintf() */

    /* Output a character */
    void (*putc)(struct printf_info *info, char ch);
};


typedef struct printfStruct{
    /* 数据缓存 */
    char *stringsHead;
    char *stringsNow;

    /* 输出函数 */
    int8_t (*cPutChar)(struct printfStruct *ptypeHandle, char ch);
    int8_t (*cPutStrings)(struct printfStruct *ptypeHandle, char *pcStrings);
} printfTypeDef;


int32_t honrunVprintfLength(const char *fmt, honrun_va_list va);
int32_t honrunVprintfString(printfTypeDef *ptypeHandle, const char *fmt, honrun_va_list va);

int honrunSprintf(char *buf, const char *fmt, ...);
int32_t honrunSprintfLength(const char *fmt, ...);
int32_t honrunSprintfString(const char *fmt, ...);


#endif
